#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPainter>
#include <QImage>
#include <QRect>
#include <QList>
#include <QString>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setWindowFlag(Qt::WindowMaximizeButtonHint, false);
    this->input = new InputForm;
    this->connect(this->input, SIGNAL(closeInputForm()),
                  this, SLOT(closeInputForm()));
}

MainWindow::~MainWindow()
{
    delete this->input;
    this->input = nullptr;
    delete ui;
}

void MainWindow::paintEvent(QPaintEvent *) {
    QPainter p(this);
    QImage image(":/bg/gojyuonn.png");
    QRect r;
    r.setTop(25);
    r.setWidth(this->width());
    r.setHeight(this->height() - 25);
    p.drawImage(r, image);
}

void MainWindow::closeInputForm() {
    this->ui->menuBar->setVisible(true);
}

void MainWindow::on_hiragana_triggered()
{
    QList<QString> hiragana, romaji;
    QString str = "あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをん";
    romaji.append("a");romaji.append("i");romaji.append("u");romaji.append("e");romaji.append("o");
    romaji.append("ka");romaji.append("ki");romaji.append("ku");romaji.append("ke");romaji.append("ko");
    romaji.append("sa");romaji.append("shi");romaji.append("su");romaji.append("se");romaji.append("so");
    romaji.append("ta");romaji.append("chi");romaji.append("tsu");romaji.append("te");romaji.append("to");
    romaji.append("na");romaji.append("ni");romaji.append("nu");romaji.append("ne");romaji.append("no");
    romaji.append("ha");romaji.append("hi");romaji.append("fu");romaji.append("he");romaji.append("ho");
    romaji.append("ma");romaji.append("mi");romaji.append("mu");romaji.append("me");romaji.append("mo");
    romaji.append("ya");romaji.append("yu");romaji.append("yo");
    romaji.append("ra");romaji.append("ri");romaji.append("ru");romaji.append("re");romaji.append("ro");
    romaji.append("wa");romaji.append("wo");romaji.append("n");
    int str_len = str.length();
    for (int i = 0; i < str_len; ++i) {
        hiragana.append(str.at(i));
    }
    this->input->setRomaji(romaji);
    this->input->setTextList(hiragana);
    this->input->show();
}


void MainWindow::on_katakana_triggered()
{
    QList<QString> katakana, romaji;
    QString str = "アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン";
    romaji.append("a");romaji.append("i");romaji.append("u");romaji.append("e");romaji.append("o");
    romaji.append("ka");romaji.append("ki");romaji.append("ku");romaji.append("ke");romaji.append("ko");
    romaji.append("sa");romaji.append("shi");romaji.append("su");romaji.append("se");romaji.append("so");
    romaji.append("ta");romaji.append("chi");romaji.append("tsu");romaji.append("te");romaji.append("to");
    romaji.append("na");romaji.append("ni");romaji.append("nu");romaji.append("ne");romaji.append("no");
    romaji.append("ha");romaji.append("hi");romaji.append("fu");romaji.append("he");romaji.append("ho");
    romaji.append("ma");romaji.append("mi");romaji.append("mu");romaji.append("me");romaji.append("mo");
    romaji.append("ya");romaji.append("yu");romaji.append("yo");
    romaji.append("ra");romaji.append("ri");romaji.append("ru");romaji.append("re");romaji.append("ro");
    romaji.append("wa");romaji.append("wo");romaji.append("n");
    int str_len = str.length();
    for (int i = 0; i < str_len; ++i) {
        katakana.append(str.at(i));
    }
    this->input->setRomaji(romaji);
    this->input->setTextList(katakana);
    this->input->show();
}


void MainWindow::on_kana_triggered()
{
    QList<QString> kana, romaji, romaji1;
    QString str1 = "あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをん";
    QString str2 = "アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン";
    romaji1.append("a");romaji1.append("i");romaji1.append("u");romaji1.append("e");romaji1.append("o");
    romaji1.append("ka");romaji1.append("ki");romaji1.append("ku");romaji1.append("ke");romaji1.append("ko");
    romaji1.append("sa");romaji1.append("shi");romaji1.append("su");romaji1.append("se");romaji1.append("so");
    romaji1.append("ta");romaji1.append("chi");romaji1.append("tsu");romaji1.append("te");romaji1.append("to");
    romaji1.append("na");romaji1.append("ni");romaji1.append("nu");romaji1.append("ne");romaji1.append("no");
    romaji1.append("ha");romaji1.append("hi");romaji1.append("fu");romaji1.append("he");romaji1.append("ho");
    romaji1.append("ma");romaji1.append("mi");romaji1.append("mu");romaji1.append("me");romaji1.append("mo");
    romaji1.append("ya");romaji1.append("yu");romaji1.append("yo");
    romaji1.append("ra");romaji1.append("ri");romaji1.append("ru");romaji1.append("re");romaji1.append("ro");
    romaji1.append("wa");romaji1.append("wo");romaji1.append("n");
    int str_len = str1.length();
    for (int i = 0; i < str_len; ++i) {
        kana.append(str1.at(i));
        romaji.append(romaji1.at(i));
        kana.append(str2.at(i));
        romaji.append(romaji1.at(i));
    }
    this->input->setRomaji(romaji);
    this->input->setTextList(kana);
    this->input->show();
}


void MainWindow::on_voiced_triggered()
{
    QList<QString> kana, romaji, romaji1;
    QString str1 = "がぎぐげござじずぜぞだぢづでどばびぶべぼぱぴぷぺぽ";
    QString str2 = "ガギグゲゴザジズゼゾダジヅデドバビブベボパピプペポ";
    romaji1.append("ga");romaji1.append("gi");romaji1.append("gu");romaji1.append("ge");romaji1.append("go");
    romaji1.append("za");romaji1.append("ji");romaji1.append("zu");romaji1.append("ze");romaji1.append("zo");
    romaji1.append("da");romaji1.append("ji");romaji1.append("du");romaji1.append("de");romaji1.append("do");
    romaji1.append("ba");romaji1.append("bi");romaji1.append("bu");romaji1.append("be");romaji1.append("bo");
    romaji1.append("pa");romaji1.append("pi");romaji1.append("pu");romaji1.append("pe");romaji1.append("po");
    int str_len = str1.length();
    for (int i = 0; i < str_len; ++i) {
        kana.append(str1.at(i));
        romaji.append(romaji1.at(i));
        kana.append(str2.at(i));
        romaji.append(romaji1.at(i));
    }
    this->input->setRomaji(romaji);
    this->input->setTextList(kana);
    this->input->show();
}


void MainWindow::on_youon_triggered()
{
    QList<QString> kana, romaji;
    QString str1 = "きゃきゅきょぎゃぎゅぎょしゃしゅしょじゃじゅじょちゃちゅちょじゃじゅじょにゃにゅにょひゃひゅひょびゃびゅびょぴゃぴゅぴょみゃみゅみょりゃりゅりょ";
    QString str2 = "キャキュキョギャギュギョシャシュショジャジュジョチャチュチョジャジュジョニャニュニョヒャヒュヒョビャビュビョピャピュピョミャミュミョリャリュリョ";
    QString romaji_str = "kyakyukyogyagyugyosyasyusyojyajyujyocyacyucyojyajyujyonyanyunyohyahyuhyobyabyubyopyapyupyomyamyumyoryaryuryo";
    int str_len = str1.length();
    for (int i = 0, j = 0; i < str_len; i += 2, j += 3) {
        kana.append(QString(str1.at(i)) + QString(str1.at(i + 1)));
        romaji.append(QString(romaji_str.at(j)) + QString(romaji_str.at(j + 1)) + QString(romaji_str.at(j + 2)));
        kana.append(QString(str2.at(i)) + QString(str2.at(i + 1)));
        romaji.append(QString(romaji_str.at(j)) + QString(romaji_str.at(j + 1)) + QString(romaji_str.at(j + 2)));
    }
    this->input->setRomaji(romaji);
    this->input->setTextList(kana);
    this->input->show();
}

